import { polarPoints } from "../algorithm/polar.js";
import { _transform } from '../math/transform.js'
import { _mirrorPoints } from '../algorithm/mirror.js'
import { _path } from './path.js'
import { _props } from "./canvas.js";
import { _mirrorColor } from '../common/index.js'


export const _polygon = (ctx, options, props) => {
    let points = polarPoints(options)
    let { transform, mirror, pathMode = 'LINE_LOOP' } = options
    // 变形函数
    points = _transform(points, transform)
    points = _mirrorPoints(points, mirror)
    let color = _mirrorColor(mirror)

    ctx.save();
    _props(ctx, props)
    _path(ctx, {
        ...options,
        points,
        pathMode,
        mirror: null,
        color
    }, props)
    ctx.restore();
}

export const _rect = (ctx, options, props) => {
    options.n = 4
    _polygon(ctx, options, props)
}
